import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
class Header extends Component {
  go = () => {
    this.props.history.go(2);
  };

  goBack = () => {
    this.props.history.goBack();
  };

  goForWard = () => {
    this.props.history.goForward();
  };
  render() {
    return (
      <div>
        <h2>React Router Demo</h2>
        <button onClick={this.go}>go</button>&nbsp;
        <button onClick={this.goBack}>goBack</button>&nbsp;
        <button onClick={this.goForWard}>goForWard</button>
      </div>
    );
  }
}

export default withRouter(Header);

// withRouter 可以加工一般组件，让一般组件具有路由组件的所有特有的API
// withRouter 的返回值是一个新组件
